package 面向对象高级.static关键字;

public class Chinese {
    String name;
    int age;
    static String nation;

    public Chinese() {
        showPrint();
    }

    public Chinese(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //静态的方法
    public static void showPrint(){
        //在静态内部访问静态的变量
        System.out.println(nation);
        System.out.println("我是一个中国人");
        //在静态内部访问非静态成员
    }

    public void a(){
        showPrint();
    }

    //代码块
    {
        showPrint();
    }

    @Override
    public String toString() {
        return "Chinese{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", nation='" + nation + '\'' +
                '}';
    }
}

class ChineseTest{
    public static void main(String[] args) {
        Chinese chinese=null;
        chinese.showPrint();
//        Chinese chinese1 = new Chinese("张三",23);
//        chinese1.nation="中国";
//        System.out.println(chinese1);
//
//        Chinese chinese2 = new Chinese("李四",34);
//        System.out.println(chinese2);
//
//        System.out.println(chinese1.nation);
//        //推荐使用第二种方法
//        System.out.println(Chinese.nation);
    }
}

class ChineseA extends Chinese{
    public static void b(){
        System.out.println(nation);
    }
}
